package com.csii.mobilebanking.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.csii.mobilebanking.R;


import android.content.Context;
import android.text.TextUtils;

/**
 * 得到group 和child的数据
 * 
 * @author Administrator
 * 
 */
public class GroupChildUtil {

	// 绑定的组Id的名字
	public static String groupIdFrom = "group_id";
	// 绑定的组name的名字
	public static String groupNameFrom = "group_name";
	// 绑定的内容Id的名字
	public static String childIdFrom = "child_id";
	// 绑定的内容Name的名字
	public static String childNameFrom = "child_name";

	// 组布局文件id
	private static int groupLayout = R.layout.exp_group;
	// 内容布局文件id
	private static int childLayout = R.layout.exp_child;
	// 组Id绑定控件Id
	// private static int groupIdTo = R.id.groupIdTo;
	// // 内容Id绑定控件的Id
	// private static int childIdTo = R.id.childIdTo;
	// // 组名称绑定的控件Id
	// private static int groupNameTo = R.id.groupNameTo;
	// // 内容Id绑定的控件Id
	// private static int childNameTo = R.id.childNameTo;
	private Context mContext;
	private List<GroupChildBean> groupChildData;

	public GroupChildUtil(Context context, List<GroupChildBean> datas) {
		this.mContext = context;
		this.groupChildData = datas;
	}

	public ExpListAdt bindAdapter() {
		// 定义构建Adpater的组要用的组数据.
		List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
		// 定义构建Adpater的子条目要用的组数据.
		List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
		// LinkedHashMap会根据添加时顺序存放数据.
		Map<Map<String, String>, List<Map<String, String>>> tempMap = new LinkedHashMap<Map<String, String>, List<Map<String, String>>>();
		if (groupChildData != null && groupChildData.size() > 0) {
			for (int i = 0; i < groupChildData.size(); i++) {
				GroupChildBean gc = groupChildData.get(i);
				Map<String, String> groupMap = new HashMap<String, String>();
				Map<String, String> childMap = new HashMap<String, String>();

				groupMap.put(groupIdFrom, gc.getListGroupBeans().get(i).getId());
				groupMap.put(groupNameFrom, gc.getListGroupBeans().get(i).getName());
//				if (TextUtils.isEmpty(gc.getChildId())
//						&& TextUtils.isEmpty(gc.getChildName())) {
//					childMap = null;
//				} else {
//					childMap.put(childIdFrom, gc.getChildId());
//					childMap.put(childNameFrom, gc.getChildName());
//				}
				// tempMap的key是组,value是组中包含的子条目List.
				if (tempMap.containsKey(groupMap)) {
					if (childMap != null) {
						tempMap.get(groupMap).add(childMap);
					}
				} else {
					List<Map<String, String>> tempList = new ArrayList<Map<String, String>>();
					if (childMap != null) {
						tempList.add(childMap);
					}
					tempMap.put(groupMap, tempList);
				}
			}
		}
		// 循环map,得到最终的group和child.
		for (Map<String, String> key : tempMap.keySet()) {
			groupData.add(key);
			childData.add(tempMap.get(key));
		}
//		ExpListAdt mAdt = new ExpListAdt(mContext, groupData, childData);
//		return mAdt;
		return null;
	}
}
